package com.lmt.api;

import com.lmt.base.ResultData;
import com.lmt.entity.Dissertation;
import com.lmt.entity.search.DissertationSearch;
import com.lmt.service.DissertationService;
import com.lmt.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Date 2018/07/17
 *
 * @author MT-Lin
 */
@RestController
@RequestMapping("/DissertationApi")
public class DissertationApi {

	private final DissertationService dissertationService;

	@Autowired
	public DissertationApi(DissertationService dissertationService) {
		this.dissertationService = dissertationService;
	}

	@RequestMapping("/save")
	public ResultData save(@RequestBody Dissertation dissertation) {
		return this.dissertationService.save(dissertation);
	}

	@RequestMapping("/search")
	public ResultData search(@RequestBody DissertationSearch dissertationSearch) {
		return this.dissertationService.search(dissertationSearch);
	}

	@RequestMapping("/findOneById")
	public ResultData findOneById(@RequestBody DissertationSearch dissertationSearch) {
		String id = dissertationSearch.getId();
		if (null == id) {
			return ResultUtil.newFail("传入的专题ID为空");
		}
		return this.dissertationService.findOneById(id);
	}

	@RequestMapping("/delete")
	public ResultData delete(@RequestBody List<Dissertation> dissertations) {
		return this.dissertationService.delete(dissertations);
	}

	@RequestMapping("/update")
	public ResultData update(@RequestBody Dissertation dissertation) {
		return this.dissertationService.update(dissertation);
	}

	@RequestMapping("/getParentTree")
	public ResultData getParentTree() {
		return this.dissertationService.getParentTree();
	}
}
